package com.ruoyi.account.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import org.springframework.core.NestedExceptionUtils;

import java.util.*;

@Getter
public enum ActionTypeEnum {

    CZ("CZ", "充值", true, Arrays.asList(AccountTypeEnum.SPECIAL.getValue())),
    TK("TK", "退款", false, Arrays.asList(AccountTypeEnum.SPECIAL.getValue(), AccountTypeEnum.ACCOUNT.getValue())),
    BD("BD", "补单", false, Arrays.asList(AccountTypeEnum.SPECIAL.getValue())),

    INCOME("INCOME", "收入", false, Arrays.asList(AccountTypeEnum.ACCOUNT.getValue())),
    ADJUST("ADJUST", "调账", true, Arrays.asList(AccountTypeEnum.ACCOUNT.getValue())),
    CHANNEL_PAYOUT("CHANNEL_PAYOUT", "采量支出", false, Arrays.asList(AccountTypeEnum.ACCOUNT.getValue())),
    COMPANY_PAYOUT("COMPANY_PAYOUT", "公司运营", false, Arrays.asList(AccountTypeEnum.ACCOUNT.getValue())),
    STAFF_SALARY("STAFF_SALARY", "员工工资", false, Arrays.asList(AccountTypeEnum.ACCOUNT.getValue())),
    STAFF_PERCENT("STAFF_PERCENT", "员工提成", false, Arrays.asList(AccountTypeEnum.ACCOUNT.getValue())),
    AGENT_REBATE("AGENT_REBATE", "代理返点", false, Arrays.asList(AccountTypeEnum.ACCOUNT.getValue())),

    ;


    public static List<String> needMainInfoList = new ArrayList<>();
    static {
        needMainInfoList.add(CZ.getValue());

        // 退款需要 入账人员 选择
//        needMainInfoList.add(TK.getValue());

        needMainInfoList.add(ADJUST.getValue());
    }

    String value;
    String name;
    boolean needMain;
    List<String> accountTypeList;

    ActionTypeEnum(String value, String name, boolean needMain, List<String> accountTypeList){
        this.value = value;
        this.name = name;
        this.needMain = needMain;
        this.accountTypeList = accountTypeList;
    }

    public String getValue() {
        return this.value;
    }

    public String getLabel() {
        return this.name;
    }

    public static String getLabelByValue(String value) {
        for (ActionTypeEnum item : values()) {
            if (StrUtil.equals(item.getValue(), value)){
                return item.getLabel();
            }
        }
        return value;
    }

    public static List<Map<String, String>> getListMap() {
        List<Map<String, String>> listMap = new ArrayList<>();
        for (ActionTypeEnum actionTypeEnum : values()) {
            Map<String, String> itemMap = new HashMap<>();
            itemMap.put("name", actionTypeEnum.getName());
            itemMap.put("value", actionTypeEnum.getValue());
            listMap.add(itemMap);
        }
        return listMap;
    }

    public static List<Map<String, Object>> getListMapByAccountType(String accountType) {
        List<Map<String, Object>> listMap = new ArrayList<>();
        for (ActionTypeEnum actionTypeEnum : values()) {
            if (actionTypeEnum.getAccountTypeList().contains(accountType)){
                Map<String, Object> itemMap = new HashMap<>();
                itemMap.put("name", actionTypeEnum.getName());
                itemMap.put("value", actionTypeEnum.getValue());
                itemMap.put("needMain", actionTypeEnum.isNeedMain());
                listMap.add(itemMap);
            }
        }
        return listMap;
    }
}
